<?php

class Application_Form_Account extends Validation_Form
{

  public function init()
  {
  	/*
  	 * data to form
  	 */
  	$academicDegreeDao = new Application_Model_Dao_AcademicDegree();
  	$academicDegrees = $academicDegreeDao->getToSelect(); 
  
  	$cathedralDao = new Application_Model_Dao_Cathedral();
  	$cathedrals = $cathedralDao->getToSelect();
  	
  	$roleDao = new Application_Model_Dao_Role();
  	$roles = $roleDao->getToSelect();
        
  	
  	/*
  	 * form
  	 */
    $this->setName("zendForm");
    $this->setMethod('post');
    
	$id = new Zend_Form_Element_Hidden('id');
	$id->addFilter('Int');

    $academicDegree = new Zend_Form_Element_Select('academicDegree_id');
   	$academicDegree->setLabel('Stopień naukowy')
   	    		   ->setMultiOptions($academicDegrees)
   	    		   ->setRequired(true)
   	    		   ->addValidator('NotEmpty', true);
    $name = $this->createElement('text', 'name');
    $name->setLabel('Imię')
         ->setRequired(TRUE)
         ->setAttrib('size', 30)
         ->addFilters(array(
            new Zend_Filter_StringTrim(),
            new Zend_Filter_StripNewlines(),
			new Zend_Filter_StripTags()
           ))
         ->addValidators(array(
            new Zend_Validate_NotEmpty(),
            new Zend_Validate_StringLength(array('min' => 2, 'max' => 30)),
            new Zend_Validate_Alpha()
            ));
    $surname = $this->createElement('text', 'surname');
    $surname->setLabel('Nazwisko')
            ->setRequired(TRUE)
            ->setAttrib('size', 30)
            ->addFilters(array(
                new Zend_Filter_StringTrim(),
                new Zend_Filter_StripNewlines(),
                new Zend_Filter_StripTags()
            ))
            ->addValidators(array(
                new Zend_Validate_NotEmpty(),
                new Zend_Validate_StringLength(array('min' => 2, 'max' => 30)),
                new Zend_Validate_Alpha()
            ));
    $email = $this->createElement('text', 'email');
    $email->setLabel('E-mail')
            ->setRequired(TRUE)
            ->setAttrib('size', 30)
            ->addFilters(array(
                new Zend_Filter_StringToLower(),
                new Zend_Filter_StringTrim(),
                new Zend_Filter_StripNewlines(),
                new Zend_Filter_StripTags()
            ))
            ->addValidators(array(
                new Zend_Validate_EmailAddress(),
                new Zend_Validate_NotEmpty()
            ));
   $password = $this->createElement('password', 'password');
   $password->setLabel('Hasło')
            ->setRequired(true)
            ->setAttrib('size', 30)
            ->addFilters(array(
                new Zend_Filter_StringToLower(),
                new Zend_Filter_StringTrim(),
                new Zend_Filter_StripNewlines(),
                new Zend_Filter_StripTags()
            ))
            ->addValidators(array(
                new Zend_Validate_NotEmpty(),
                new Zend_Validate_StringLength(array('min' => 5, 'max' => 30))
            ));
   $passwordRepeat = $this->createElement('password', 'passwordRepeat');
   $token = Zend_Controller_Front::getInstance()->getRequest()->getPost('password');;
   $passwordRepeat->setLabel('Powtórz hasło')
            ->setRequired(true)
            ->setAttrib('size', 30)
            ->addFilters(array(
                new Zend_Filter_StringToLower(),
                new Zend_Filter_StringTrim(),
                new Zend_Filter_StripNewlines(),
                new Zend_Filter_StripTags()
            ))
            ->addValidators(array(
            	new Zend_Validate_Identical(trim($token)),
                new Zend_Validate_NotEmpty()
                
                
            ));
   $cathedral = new Zend_Form_Element_Select('cathedral_id');
   $cathedral->setLabel('Katedra')
   	     	 ->setMultiOptions($cathedrals)
    	 	 ->setRequired(true)
    	 	 ->addValidator('NotEmpty', true);
   $role = new Zend_Form_Element_Select('role_id');
   $role->setLabel('Uprawnienia')
   	    ->setMultiOptions($roles)
    	->setRequired(true)
    	->addValidator('NotEmpty', true); 
    	
    $lecturer = $this->createElement('checkbox','lecturer');
	$lecturer->setLabel('Wykładowca');
	
	$typeForm = $this->createElement('hidden','typeForm');
	
   	$submit = new Zend_Form_Element_Submit('submit');
	$submit->setAttrib('id', 'submit');
    
    $this->addElements(array(
    	$id,
    	$academicDegree,
        $name,
        $surname,
        $email,
        $password,
        $passwordRepeat,
        $cathedral,
        $role,
        $lecturer,
        $typeForm,
        $submit,
        ));
  }


}

	